package com.cls.business.strategy.impl.notice;

import com.cls.business.entity.DeclareTopic;
import com.cls.business.entity.Notice;
import com.cls.business.entity.Topic;
import com.cls.business.entity.TopicPlan;
import com.cls.business.service.*;
import com.cls.business.strategy.NoticeStrategy;
import com.cls.common.enums.DictEnum;
import com.cls.common.enums.MessageEnum;
import com.cls.common.exception.MyException;
import com.cls.system.entity.User;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 结项结果公告的实现方法
 *
 * @author Administrator
 */
@Component("notice_type_jxjggg")
@RequiredArgsConstructor
public class JXJGGGNoticeImpl implements NoticeStrategy {
    private final INoticeService noticeService;
    private final ITopicPlanService topicPlanService;

    @Override
    public void createNotice(Notice notice) {
        String period = notice.getPeriod();
        TopicPlan topicPlan = topicPlanService.selectByPeriod(period);
        if (topicPlan == null) {
            throw new MyException("对不起，当前委托课题排班不存在！");
        }
        //把当前计划的状态改为已结项完成
        topicPlan.setStatusCode(DictEnum.PLAN_CONCLUDE_FINISH.getCode());
        noticeService.save(notice);
        topicPlan.setConcludeFinishNoticeId(notice.getNoticeId());
        topicPlanService.updateById(topicPlan);

    }
}
